<form id="config-form" class="form-horizontal" role="form" method="post">
    <div class="panel panel-default panel-intro">
        <div class="panel-heading">
            <div class="panel-title">考勤配置</div>
        </div>
        <div class="panel-body">
            <div class="form-group">
                <label class="col-sm-2 control-label">上班时间:</label>
                <div class="col-sm-4">
                    <input type="time" name="work_start_time" class="form-control" value="{$config.work_start_time|default='09:00'}" required />
                </div>
                
                <label class="col-sm-2 control-label">下班时间:</label>
                <div class="col-sm-4">
                    <input type="time" name="work_end_time" class="form-control" value="{$config.work_end_time|default='18:00'}" required />
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-2 control-label">迟到阈值（分钟）:</label>
                <div class="col-sm-4">
                    <input type="number" name="late_threshold" class="form-control" value="{$config.late_threshold|default='10'}" required />
                </div>
                
                <label class="col-sm-2 control-label">早退阈值（分钟）:</label>
                <div class="col-sm-4">
                    <input type="number" name="early_leave_threshold" class="form-control" value="{$config.early_leave_threshold|default='10'}" required />
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-2 control-label">有效打卡距离（米）:</label>
                <div class="col-sm-4">
                    <input type="number" name="clock_in_distance" class="form-control" value="{$config.clock_in_distance|default='500'}" required />
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-2 control-label">办公地点地址:</label>
                <div class="col-sm-10">
                    <input type="text" name="office_address" class="form-control" value="{$config.office_address|default=''}" placeholder="请输入办公地点详细地址" />
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-2 control-label">办公地点经度:</label>
                <div class="col-sm-4">
                    <input type="text" name="office_longitude" class="form-control" value="{$config.office_longitude|default=''}" placeholder="例: 106.12345" />
                </div>
                
                <label class="col-sm-2 control-label">办公地点纬度:</label>
                <div class="col-sm-4">
                    <input type="text" name="office_latitude" class="form-control" value="{$config.office_latitude|default=''}" placeholder="例: 29.12345" />
                </div>
            </div>
            
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-primary">保存配置</button>
                </div>
            </div>
        </div>
    </div>
</form>

<script>
$(function() {
    $('#config-form').on('submit', function(e) {
        e.preventDefault();
        
        $.ajax({
            url: '{:url("hr/attendance/config")}',
            type: 'POST',
            data: $(this).serialize(),
            dataType: 'json',
            success: function(res) {
                if (res.code == 1) {
                    Toastr.success(res.msg);
                } else {
                    Toastr.error(res.msg);
                }
            },
            error: function() {
                Toastr.error('保存失败');
            }
        });
    });
});
</script>
